SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS OFF
GO
CREATE PROCEDURE [dbo].[EspacioUsado] AS
SET NOCOUNT ON
select sysobjects.name AS Tabla
, sum(case when sysindexes.indid<2 then rows 
else 0 end) as Registros 
, sum(case when sysindexes.indid in (0,1,255) then sysindexes.reserved 
else 0 end) * 8 as ReservadoKB 
, sum(case when sysindexes.indid in (0,1) then sysindexes.dpages 
when sysindexes.indid=255 then sysindexes.used 
else 0 end) * 8 as DatosKB 
, (sum(case when sysindexes.indid in (0,1,255) then sysindexes.used 
else 0 end) 
- sum(case when sysindexes.indid in (0,1) then sysindexes.dpages 
when sysindexes.indid=255 then sysindexes.used 
else 0 end))*8 as IndiceKB 
, (sum(case when sysindexes.indid in (0,1,255) then 
sysindexes.reserved-sysindexes.used 
else 0 end)*8) as SinUsarKB
from sysobjects 
join sysindexes 
on sysobjects.id=sysindexes.id 
where xtype='U' 
group by sysobjects.name 
order by 2 desc
GO
